#!/bin/bash
#

#检测是否存在软件包
FR(){
	rpm -qa|grep '$FW' &> /dev/null
	if [ $? -eq 0 ];then
		:
	else
		echo "未安装$FW"
	fi
}
#检查端口
FD(){
    netstat -tunlp|grep '$FW' &> /dev/null
	if [ $? -eq 0 ];then	
		echo "端口被占用"
	else
		:
	fi
}
#检擦防火墙
FF(){
	systemctl status firewalld &> /dev/null
	if [ $? -eq 0 ];then
		:
	echo
		echo "防火墙未关闭"
	fi	
}

read -p "输入需要启动的服务: " FW

systemctl start $FW &> /dev/null

if [ $? -eq 0 ];then
	echo "${FW}正常启动"
elif [ `ps -elf | grep $FW | sed "/grep/d" | wc -l` -gt 0 ] &> /dev/null;then
	echo "${FW}已经启动"
else
	FR
	FD
	FF
fi

